<template>
  <div class="app-container">
    <header class="app-header">
      <div class="header-content">
        <h1 class="site-title">
          <router-link to="/">Wave Blog</router-link>
        </h1>
        
        <!-- 移动端菜单按钮 -->
        <button class="menu-toggle" @click="menuOpen = !menuOpen" aria-label="菜单">
          <span class="menu-icon"></span>
        </button>
        
        <!-- 桌面端导航 -->
        <nav class="main-nav desktop-nav">
          <router-link to="/" class="nav-link">首页</router-link>
          <router-link to="/article" class="nav-link">文章</router-link>
          <router-link to="/admin" class="nav-link">管理</router-link>
        </nav>
        
        <!-- 移动端导航 -->
        <nav class="main-nav mobile-nav" :class="{ 'active': menuOpen }">
          <router-link to="/" class="nav-link" @click="menuOpen = false">首页</router-link>
          <router-link to="/article" class="nav-link" @click="menuOpen = false">文章</router-link>
          <router-link to="/admin" class="nav-link" @click="menuOpen = false">管理</router-link>
        </nav>
      </div>
    </header>
    
    <main class="app-main">
      <div class="container">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </div>
    </main>
    
    <footer class="app-footer">
      <div class="container">
        <div class="footer-content">
          <p>© {{ new Date().getFullYear() }} Wave Blog. All rights reserved.</p>
        </div>
      </div>
    </footer>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      menuOpen: false
    }
  },
  mounted() {
    // 监听窗口大小变化，关闭移动端菜单
    window.addEventListener('resize', this.handleResize)
  },
  beforeUnmount() {
    window.removeEventListener('resize', this.handleResize)
  },
  methods: {
    handleResize() {
      if (window.innerWidth >= 768) {
        this.menuOpen = false
      }
    }
  }
}
</script>

<style>
/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f5f5f5;
}

/* 应用容器 */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 容器类 - 用于响应式布局 */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 头部样式 */
.app-header {
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-content {
  width: 100%;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
}

.site-title {
  font-size: 1.5rem;
  font-weight: bold;
}

.site-title a {
  color: #333;
  text-decoration: none;
}

/* 菜单按钮 - 移动端 */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  z-index: 1001;
}

.menu-icon {
  display: block;
  width: 25px;
  height: 3px;
  background-color: #333;
  position: relative;
  transition: background-color 0.3s;
}

.menu-icon::before,
.menu-icon::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 3px;
  background-color: #333;
  transition: transform 0.3s;
}

.menu-icon::before {
  top: -8px;
}

.menu-icon::after {
  bottom: -8px;
}

/* 桌面端导航 */
.desktop-nav {
  display: flex;
  gap: 20px;
}

.nav-link {
  color: #666;
  text-decoration: none;
  padding: 5px 10px;
  transition: color 0.3s;
  white-space: nowrap;
}

.nav-link:hover {
  color: #333;
}

/* 移动端导航 */
.mobile-nav {
  display: none;
  position: fixed;
  top: 0;
  right: -100%;
  width: 70%;
  height: 100vh;
  background-color: #fff;
  flex-direction: column;
  padding: 80px 20px;
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.1);
  transition: right 0.3s;
  gap: 20px;
}

.mobile-nav.active {
  right: 0;
}

/* 主内容区域 */
.app-main {
  flex: 1;
  padding: 40px 0;
}

/* 页脚样式 */
.app-footer {
  background-color: #333;
  color: #fff;
  padding: 20px 0;
  margin-top: auto;
}

.footer-content {
  text-align: center;
}

/* 页面过渡动画 */
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter-from, .fade-leave-to {
  opacity: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .menu-toggle {
    display: block;
  }
  
  .desktop-nav {
    display: none;
  }
  
  .mobile-nav {
    display: flex;
  }
  
  .app-main {
    padding: 20px 0;
  }
  
  .site-title {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .header-content,
  .container {
    padding: 0 15px;
  }
  
  .app-main {
    padding: 15px 0;
  }
  
  .mobile-nav {
    width: 80%;
  }
}
</style>
